package cn.springsoter.core.launch.listener;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;

import cn.springsoter.core.launch.server.ServerInfo;
import lombok.extern.slf4j.Slf4j;

/**
 * 项目启动事件通知
 *
 * @author kevin
 */
@Slf4j
@Configuration
public class StartEventListener {

	@Autowired
	private ServerInfo serverInfo;
	
//	@Async
//	@Order
	@EventListener(WebServerInitializedEvent.class)
	public void afterStart(WebServerInitializedEvent event) {
		Environment environment = event.getApplicationContext().getEnvironment();
		String appName = environment.getProperty("spring.application.name").toUpperCase();
		String logPath = environment.getProperty("logging.file.path");
		String profile = StringUtils.arrayToCommaDelimitedString(environment.getActiveProfiles());
		
		log.info("---[{}#{}]---启动完成，访问地址:[http://{}]，日志地址:[{}]---", appName, profile, serverInfo.getIpWithPort(), logPath);
	}
}
